Skip to content

Revise code generation for parameters#1002

Merged
thomas-bc merged 45 commits into
mainfrom
issue-984-extern-param-defaults
Jun 3, 2026
Merged

Revise code generation for parameters#1002
thomas-bc merged 45 commits into
mainfrom
issue-984-extern-param-defaults

Conversation

@bocchino

@bocchino bocchino commented May 5, 2026

Copy link
Copy Markdown
Collaborator
  • Make the behavior of external parameters consistent with the behavior of internal parameters. In particular, respect the default values provided for external parameters.
  • Move the scratch parameter buffer from the stack to a component instance member, to avoid overflowing the stack.
  • Clean up the generated code.

Closes #984.

Tandem with https://github.com/bocchino/fprime/tree/fpp-issue-984-extern-param-defaults.

Implementation Note

In the old code for loading external parameters, if there was no valid value to send to the external parameter interface, the interface was never called. In the new code, the interface is called with an INVALID flag argument. The new behavior provides more information to the external interface. However, the external interface will need to respect the rule that if it is called with an INVALID flag argument, then the data buffer does not contain valid data.

Review Notes

The diff of the C++ output for the component base classes may be hard to review. Here is a simple model that illustrates the new code generation strategy:

module Fw {
  port Time
  port PrmGet
  port PrmSet
  port Cmd
  port CmdResponse
  port CmdReg
}

passive component C {

  time get port timeGetOut

  param get port paramGet

  param set port paramSet

  command recv port cmdIn

  command resp port cmdResponseOut

  command reg port cmdRegIn

  param InternalU32Default: U32 default 42

  external param ExternalU32Default: U32 default 42

  param InternalU32NoDefault: U32

  external param ExternalU32NoDefault: U32

}

You can run this model through fpp-to-cpp to see the four cases: internal parameter with default, external parameter with default, internal parameter with no default, and external parameter with no default.

@bocchino bocchino requested review from Kronos3 and LeStarch May 5, 2026 22:32
@bocchino bocchino added the fprime-fpp tandem F Prime and FPP tandem development label May 5, 2026

@Kronos3 Kronos3 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this codegen looks good though we may want to revisit the use of the scratch buffer instead of stack buffer in the future.

@LeStarch LeStarch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some issues found

Comment thread compiler/tools/fpp-to-cpp/test/component/base/QueuedTestComponentAc.ref.cpp Outdated
@bocchino bocchino requested a review from LeStarch May 28, 2026 04:25
@bocchino

Copy link
Copy Markdown
Collaborator Author

@LeStarch I re-ran Devin and it found one more issue: in the auto-generated paramGet functions, we should not declare _paramBuffer in the case of an internal parameter. This variable is unused in that case. I will fix this issue, and then the PR should be ready to go!

Remove unused variable
@bocchino

bocchino commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator Author

@LeStarch The issue flagged by Devin is fixed. Can you approve?

@bocchino bocchino added the alpha release Branch is holding an alpha release that is not merged to main label Jun 2, 2026
@thomas-bc thomas-bc merged commit d54f529 into main Jun 3, 2026
37 checks passed
@bocchino bocchino deleted the issue-984-extern-param-defaults branch June 3, 2026 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

alpha release Branch is holding an alpha release that is not merged to main fprime-fpp tandem F Prime and FPP tandem development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default External Parameters Do Not Enforce Defaults

4 participants